package com.anpxd.erpad.bean

import android.annotation.SuppressLint
import android.graphics.Region
import android.provider.ContactsContract
import com.gg.utils.DateUtils
import com.google.gson.annotations.SerializedName
import com.socks.library.KLog
import java.text.SimpleDateFormat
import java.util.*


/**
 *  Creator : GG
 *  Time    : 2017/11/22
 *  Mail    : gg.jin.yu@gmail.com
 *  Explain :
 */

data class Car(
        @SerializedName("brand") var brand: Brand? = Brand(),
        @SerializedName("brandId") var brandId: Int? = 0, //2
        @SerializedName("car4sUpkeepState") var car4sUpkeepState: Int? = 0, //1
        @SerializedName("carAgeRemark") var carAgeRemark: String? = "", //1年内
        @SerializedName("carAuthState") var carAuthState: Int? = 0, //1
        @SerializedName("carBargainPriceState") var carBargainPriceState: Int? = 0, //0
        @SerializedName("carBusinessInsuranceDate") var carBusinessInsuranceDate: Long? = null, //1510675200000
        @SerializedName("carCreateTime") var carCreateTime: Long? = null, //1510710772000
        @SerializedName("carDetectState") var carDetectState: Int? = 0, //2
        @SerializedName("carDisplacement") var carDisplacement: String? = "", //3.6T
        @SerializedName("carDoorNum") var carDoorNum: Int? = 0, //4
        @SerializedName("carEnviron") var carEnviron: String? = "", //国IV
        @SerializedName("carFacotryDate") var carFacotryDate: Long? = null, //1510675200000
        @SerializedName("carFixedPriceState") var carFixedPriceState: Int? = 0, //0
        @SerializedName("carFlawDesc") var carFlawDesc: String? = "--", //工工工工工
        @SerializedName("carFloorPrice") var carFloorPrice: Double? = 0.0, //5.5
        @SerializedName("carForceInsuranceDate") var carForceInsuranceDate: Long? = null, //1510675200000
        @SerializedName("carImageUrl") var carImageUrl: String? = null,//http://47.93.47.216:8083/group1/M00/00/01/wKgAvFoSqo2AbAxVAAGLtchij08999.png
        @SerializedName("carFuel") var carFuel: String? = "", //汽油
        @SerializedName("carGearbox") var carGearbox: String? = "", //自动
        @SerializedName("carGuidePrice") var carGuidePrice: Double? = 0.0, //6
        @SerializedName("carId") var carId: String? = "", //123
        @SerializedName("carImages") var carImages: ArrayList<CarImage>? = arrayListOf(),
        @SerializedName("carImage") var carImage: CarImage? = null,
        @SerializedName("carInColor") var carInColor: String? = "", //其它
        @SerializedName("carKeyNum") var carKeyNum: Int? = 0, //4
        @SerializedName("carLicenceDate") var carLicenceDate: Long? = 0, //1510675200000
        @SerializedName("carLicenceStatus") var carLicenceStatus: Int? = 0, //0
        @SerializedName("carLocationCityName") var carLocationCityName: String? = "", //北京
        @SerializedName("carMileage") var carMileage: Double? = 0.0, //2
        @SerializedName("carMortgageDesc") var carMortgageDesc: String? = "--", //木林要要
        @SerializedName("carMortgageState") var carMortgageState: Int? = 0, //0
        @SerializedName("carNetworkPrice") var carNetworkPrice: Double? = 0.0, //1
        @SerializedName("carOrderState") var carOrderState: Int? = 0, //1
        @SerializedName("carOutColor") var carOutColor: String? = "", //其它
        @SerializedName("carPlate") var carPlate: String? = "", //京A88888
        @SerializedName("carRedAge") var carRedAge: Int? = 0, //45
        @SerializedName("carRemark") var carRemark: String? = "", //nbnbnbbnb
        @SerializedName("carRetailPrice") var carRetailPrice: Double? = 0.0, //5.8
        @SerializedName("carSaleState") var carSaleState: Int? = 0, //2
        @SerializedName("carSellingPointDesc") var carSellingPointDesc: String? = "--", //哈哈哈 这是一个卖点描述
        @SerializedName("carShowPrice") var carShowPrice: Double? = 0.0, //1
        @SerializedName("carStockState") var carStockState: Int? = 0, //2
        @SerializedName("carTaxPrice") var carTaxPrice: Double? = 0.0, //5.5
        @SerializedName("carTitle") var carTitle: String? = "", //nbnb
        @SerializedName("carTransferState") var carTransferState: Int? = 0, //0
        @SerializedName("carType") var carType: CarType? = CarType(),
        @SerializedName("carTypeId") var carTypeId: Int? = 0, //2
        @SerializedName("carUpdateTime") var carUpdateTime: Long? = 0, //1510800840000
        @SerializedName("carValidateDate") var carValidateDate: Long? = null, //1510675200000
        @SerializedName("carVin") var carVin: String? = "", //123
        @SerializedName("carVin6") var carVin6: String? = "", //123
        @SerializedName("carYellowAge") var carYellowAge: Int? = 0, //30
        @SerializedName("marketId") var marketId: String? = "", //138
        @SerializedName("model") var model: Model? = Model(),
        @SerializedName("modelId") var modelId: Int? = 0, //4
        @SerializedName("region") var region: Region? = Region(),
        @SerializedName("regionId") var regionId: String? = "", //17111017295895539072265639535439
        @SerializedName("series") var series: Series? = Series(),
        @SerializedName("seriesId") var seriesId: Int? = 0, //2
        @SerializedName("shop") var shop: Shop? = Shop(),
        @SerializedName("shopId") var shopId: String? = "", //17111013065235254074399782052879
        @SerializedName("stockAgeRemark") var stockAgeRemark: String? = "", //30～60天
        @SerializedName("userId") var userId: String? = "", //1
        @SerializedName("carVehicletaxDate") var carVehicletaxDate: Long? = null,//车船税有效时间
        @SerializedName("carTransferNum") var carTransferNum: Int? = null,//过户次数
        @SerializedName("carExtendedWarranty") var carExtendedWarranty: Int? = 0,//延保服务
        @SerializedName("carFinanceService") var carFinanceService: Int? = 0,//金融服务
        @SerializedName("carInletModel") var carInletModel: String? = "",
        @SerializedName("saleUserId") var saleUserId: String? = null,//过户次数
        @SerializedName("user") var user: User? = User(),//过户次数
        var carDisplacementUnit: String? = "L", //3.6T
        var licenseDate: String? = null,
        var factoryDate: String? = null,
        var vehicleTaxDate: String? = null,
        var businessInsuranceDate: String? = null,
        var validateDate: String? = null,
        var forceInsuranceDate: String? = null,
        var isShow: Boolean = false
) {
    fun getTransfer(): String? {
        if (carTransferState == 0)
            return "不包含过户费"
        else if (carTransferState == 1)
            return "包含过户费"
        return null
    }

    fun getFixedPrice(): String? {
        if (carFixedPriceState == 0)
            return "不是一口价"
        else if (carFixedPriceState == 1)
            return "是一口价"
        return null
    }

    fun getStock(): String = when (carStockState) {
        0 -> "未完成入库"
        10 -> "入库审核"
        20 -> "已入库"
        30 -> "出库审核中"
        40 -> "已出库"
        else -> "--"
    }

    fun getFinanceShow(): Boolean = carFinanceService == 1

    fun getWarrantShow() = carExtendedWarranty == 1

    @SuppressLint("SimpleDateFormat")
    fun getLicenceDate(): String = SimpleDateFormat("yyyy年MM月").format(Date(carLicenceDate
            ?: 0))


    fun getMileage() = "${carMileage}万公里"

    fun getGearbox() = "$carGearbox"

    fun getDisplacement() = "$carDisplacement" + "$carInletModel"

    fun getInfo(): String = carMileage.toString() + "万公里/" + if (carLicenceDate != null) DateUtils.date2Str(Date(carLicenceDate!!)).substring(0, 4) + "年" else ""

    fun getCarStatus(): String {
        val sb = StringBuffer()

        sb.append(when (carStockState) {
            0 -> "未完成入库"
            10 -> "入库审核"
            20 -> "已入库"
            30 -> "出库审核中"
            40 -> "已出库"
            else -> "--"
        })
        sb.append("/")

        sb.append(when (carAuthState) {
            0 -> {
                when (carDetectState) {
                    0 -> "未检测"
                    10 -> "检测中"
                    else -> "--"
                }
            }
            1 -> "已认证"
            else -> "--"
        })

        return sb.toString()
    }
}

//上架状态(carSaleState) 0 初始化 10 申请上架 20 上架 30 下架
//检测状态(carDetectState) 0 初始化 10 检测中 20 检测完毕
//库存状态(carStockState) 0 初始化 10 入库审核 20 入库 30 出库审核 40 出库
//认证状态(carAuthState) 0 未认证 10 已认证

data class Brand(val brandName: String = "",
                 val brandId: Int = 0,
                 val manufacturerId: Int = 0,
                 val brandLogo: String = "",
                 val brandInitial: String = "",
                 val brandPinyin: String = "",
                 val countryId: Int = 0)

data class CarImage(
        @SerializedName("carId") var carId: String? = "", //123
        @SerializedName("imageId") var imageId: String? = "", //17112118183928439410352566491473
        @SerializedName("imageKey") var imageKey: String? = "", //left_anterior
        @SerializedName("imageSeq") var imageSeq: Int? = 0, //1
        @SerializedName("imageUrl") var imageUrl: String? = null//http://47.93.47.216:8083/group1/M00/00/01/wKgAvFoSqo2AbAxVAAGLtchij08999.png
)

data class CarType(
        @SerializedName("carTypeId") var carTypeId: Int? = 0, //3
        @SerializedName("carTypeName") var carTypeName: String? = null //中大型
)

data class Region(
        @SerializedName("market") var market: Market? = Market(),
        @SerializedName("marketId") var marketId: String? = "", //138
        @SerializedName("regionCreateTime") var regionCreateTime: Long? = 0, //1510537836000
        @SerializedName("regionId") var regionId: String? = "", //17111017295895539072265639535439
        @SerializedName("regionName") var regionName: String? = "", //这是一个区域
        @SerializedName("regionNum") var regionNum: Int? = 0, //1251
        @SerializedName("regionParentId") var regionParentId: String? = "", //1
        @SerializedName("regionRemark") var regionRemark: String? = "", //12355
        @SerializedName("regionRentFee") var regionRentFee: Double? = 0.0, //15
        @SerializedName("regionState") var regionState: Int? = 0, //1
        @SerializedName("regionType") var regionType: Int? = 0 //1
)

data class Market(
        @SerializedName("marketId") var marketId: String = "", //1
        @SerializedName("marketName") var marketName: String = "" //总部
)

data class Shop(
        @SerializedName("market") var market: Market? = Market(),
        @SerializedName("marketId") var marketId: String? = "", //1
        @SerializedName("shopAddress") var shopAddress: String? = "", //三元桥
        @SerializedName("shopCreateTime") var shopCreateTime: Long? = 0, //1508831089000
        @SerializedName("shopId") var shopId: String? = "", //17102415444936682389306510396702
        @SerializedName("shopLegalMobile") var shopLegalMobile: String? = "", //18642325068
        @SerializedName("shopLegalName") var shopLegalName: String? = "", //氪荆
        @SerializedName("shopLegalNo") var shopLegalNo: String? = "", //149898989898989888
        @SerializedName("shopMobile") var shopMobile: String? = "", //15898293823
        @SerializedName("shopName") var shopName: String? = "", //车行店铺
        @SerializedName("shopState") var shopState: Int? = 0, //1
        @SerializedName("shopUpdateTime") var shopUpdateTime: Long? = 0 //1510288619000
)

data class Model(
        @SerializedName("modelGearbox") var modelGearbox: String? = "--", //手自一体变速箱(AT)
        @SerializedName("modelBody") var modelBody: String? = "--", //三厢
        @SerializedName("modelBodywork") var modelBodywork: String? = "--", //4门5座三厢
        @SerializedName("modelCylinderArray") var modelCylinderArray: String? = "--", //L
        @SerializedName("modelCylinderNum") var modelCylinderNum: String? = "--", //4
        @SerializedName("modelDisplacement") var modelDisplacement: Double? = 0.0, //1.6
        @SerializedName("modelEngineModel") var modelEngineModel: String? = "--", //5F03
        @SerializedName("modelEnviron") var modelEnviron: String? = "--", //国IV(国V)
        @SerializedName("modelFuelRoz") var modelFuelRoz: String? = "--", //汽油93号(京92号)
        @SerializedName("modelGearNum") var modelGearNum: String? = "--", //6
        @SerializedName("modelGuidePrice") var modelGuidePrice: Double? = 0.0, //24.69
        @SerializedName("modelHeight") var modelHeight: String? = "--", //1510
        @SerializedName("modelId") var modelId: Int? = 0, //4
        @SerializedName("modelInletModel") var modelInletModel: String? = "--", //T
        @SerializedName("modelLength") var modelLength: String? = "--", //4702
        @SerializedName("modelManufacturer") var modelManufacturer: String? = "--", //长安标致雪铁龙
        @SerializedName("modelName") var modelName: String? = "", //2014款 DS5LS 1.6T AT THP200 尊享
        @SerializedName("modelWheelbase") var modelWheelbase: String? = "--", //2715
        @SerializedName("modelWidth") var modelWidth: String? = "--", //1840
        @SerializedName("modelYear") var modelYear: Int? = 0, //2014
        @SerializedName("series") var series: Series? = Series(),
        @SerializedName("seriesId") var seriesId: Int? = 0, //2
        var choose: Boolean = false
)